package com.example.springbootwebflux.controller;

import com.example.springbootwebflux.domain.User;
import com.example.springbootwebflux.domain.UserBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/webflux")
public class WebFluxController {

    @GetMapping("/getInfo")
    public Mono<Map<String,Object>> getInfo(){
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code",200);
        hashMap.put("data","你好,美女");
        return Mono.just(hashMap);
    }

    /**
     * Mono直接返回数据
     * @return
     */
    @GetMapping("/getUserInfo")
    public Mono<User> getUserInfo(){
        User user = new UserBuilder().addUserNo("123456")
                .addUserName("steakliu")
                .addSex("男")
                .addDesc("帅哥一个").build();
        return Mono.just(user);
    }

    /**
     * Flux返回的是数组
     * @return
     */
    @GetMapping("/get")
    public Flux<User> get(){
        User user = new UserBuilder().addUserNo("123456")
                .addUserName("steakliu")
                .addSex("男")
                .addDesc("帅哥一个").build();
        return Flux.just(user);
    }
}
